<?php

namespace App\Models\Entity\pic_albums;

use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class pic_albums
 * @package App\Models\Entity\pic_albums
 * @version July 3, 2018, 9:34 am CST
 *
 * @property string name
 * @property string description
 * @property integer listorder
 */
class pic_albums extends Model
{
    use SoftDeletes;


    public $table = 'pic_albums';
    

    protected $dates = ['deleted_at'];


    public $fillable = [
        'name',
        'description',
        'listorder',
        'sp_id'
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'name' => 'string',
        'description' => 'string',
        'listorder' => 'integer',
        'sp_id' => 'integer',
    ];

    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [
        'name' => 'required|max:20',
        'listorder' => 'required',
        'sp_id' => 'required'
    ];


    public function sp()
    {
        return $this->belongsTo(\App\Models\Common\EntityData\Channel\Sp::class, 'sp_id');
    }


    public function posteris()
    {
        return $this->belongsToMany(\App\Models\Entity\Asset\Video\Media\Vposteri::class, 'pic_album_pics', 'pic_album_id', 'vposteri_id');
    }

    /**
     * 获得此媒资的所有标签。
     */
    public function tags()
    {
        return $this->morphToMany(\App\Models\Entity\Tag\tag::class, 'tag_content');
    }

    
}
